package com.web.action.backend;

import java.io.File;
import java.io.InputStream;
import java.io.StringBufferInputStream;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.web.util.FileUpload;
import com.web.util.PropertiesUtil;

public class UploadAction extends ActionSupport
{

	private List<File> file;

	private List<String> fileFileName;

	private List<String> fileContentType;
	
	
	private String src;
	
	private String alt;
	
	private String title; 
	
	public String getAlt() {
		return alt;
	}

	public void setAlt(String alt) {
		this.alt = alt;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getSrc() {
		return src;
	}

	public void setSrc(String src) {
		this.src = src;
	}

	public List<File> getFile()
	{
		return file;
	}

	public void setFile(List<File> file)
	{
		this.file = file;
	}

	public List<String> getFileFileName()
	{
		return fileFileName;
	}

	public void setFileFileName(List<String> fileFileName)
	{
		this.fileFileName = fileFileName;
	}

	public List<String> getFileContentType()
	{
		return fileContentType;
	}

	public void setFileContentType(List<String> fileContentType)
	{
		this.fileContentType = fileContentType;
	}

	@Override
	public String execute() throws Exception
	{
		System.out.println("uploadStart");
		List<String> uploadedFiles;
		String picsPath = ServletActionContext.getServletContext().getRealPath(
				"/product-pic");
		uploadedFiles = FileUpload.Upload(file, fileFileName, picsPath, PropertiesUtil.getDefaultProperties().getProperty("serverPath"));
		//ServletActionContext.getResponse().getWriter().print(uploadedFiles.get(0));
		//ServletActionContext.getResponse().getWriter().flush();
		//inputStream = new StringBufferInputStream(uploadedFiles.get(0));
		System.out.println(uploadedFiles.get(0));
		src = uploadedFiles.get(0);
		return INPUT;

	}

}
